const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

const Request=options=>{
  let baseURL="http://localhost:8088";

  //将method转化为大写
  options.method=options.method&&options.method.toUpperCase();

  return new Promise((resolve,reject)=>{
    wx.request({
      url: baseURL+options.url, 
      method:options.method||"GET",
      data: options.data||{},//post请求传递的参数
      header: options.header||{
        'content-type': 'application/json' 
      },
      success (res) {
        resolve(res.data)
      },
      fail(err){
        reject(err)
      }
    })
  })
  
}

//导出  module.exports
module.exports = {
  formatTime,
  Request
}
